#include "Client.h"
#include "BarberShop.h"

Client::Client(std::string const &name)
:
_name(name)
{
}

void Client::run()
{
	std::cout << "Running " << _name << std::endl;

	//while (true)
	{
		BarberShop* barberShop = BarberShop::GetInstance();

		std::cout << _name << " trying to get lock" << std::endl;
		barberShop->seatsMutex.lock();
		std::cout << _name << " succesfully got lock" << std::endl;
		
		if ( barberShop->GetCurrentSeat() < barberShop->maxSeats )
		{
			barberShop->IncreaseCurrentSeat();
		}

		for (int i = 0; i < 10; ++i)
		{
			std::cout << _name << " iteration " << i << std::endl;
		}

		barberShop->seatsMutex.unlock();
		std::cout << _name << " released lock" << std::endl;
	}
}